<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<title>项目工时统计</title>
	<script type="text/javascript" src="../../js/boot.js"></script>
</head>

<body>
	<div class="mini-splitter" style="width: 100%; height: 100%;">
		<div size="240" showCollapseButton="true">
			<div class="mini-fit">
				<ul id="pageTree" class="mini-tree" style="width: 100%;" showTreeIcon="true" allowDrag="true" allowDrop="true" textField="departName"
					idField="departID" resultAsTree="false">
				</ul>
			</div>
		</div>

		<div showCollapseButton="true">
			<fieldset id="fd1" style="width: 97%; margin-bottom: 4px;">
				<legend><span>查询条件</span></legend>
				<div id="queryForm" class="fieldset-body">
					<table class="form-table" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td class="form-label">
								<span>项目：</span>
								<input id="projectID" name="projectID" class="mini-combobox" textField="projectName" valueField="projectID" width="240">
								<span>日期从：</span>
								<input id="calendarDate_from" name="calendarDate_from" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
								<span>到：</span>
								<input id="calendarDate_to" name="calendarDate_to" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-search" onclick="doSearch()">查询</a>
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-save" onclick="output()">导出</a>
							</td>
						</tr>
					</table>
				</div>
			</fieldset>

			<div class="mini-fit">
				<div id="datagrid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="20" allowResize="true" multiSelect="true">
				</div>
			</div>
		</div>
	</div>

</body>

<script type="text/javascript">
	miniInit();

	var tree = mini.get("pageTree");
	http.get('/sys/depart/list.do', function (page) {
		tree.loadData(page);
	});
	var editNode = null; // 当前编辑的节点
	/*********************************************************
	 * 左侧目录树的鼠标点击事件
	 *********************************************************/
	tree.on("nodedblclick", function (e) {
		// debugger
		editNode = e.node;
		http.get('/sys/depart/list.do?departID=' + editNode.departID, function (page) {
			tree.addNodes(page, editNode);
			tree.expandNode(editNode);
		});
	});

	// 项目名称控件数据
	var projectCombox = mini.get("projectID");
	var projectUrl = "/oa/project/project/list.do";
	var projectData = [];
	http.get(projectUrl, function (page) {
		if (page.data.length > 0) {
			projectData.push({ projectID: "", projectName: "全部" });
			projectData = projectData.concat(page.data);
			/* for (var i = 0; i < page.data.length; i++) {
				projectData.push({ projectID: page.data[i].projectID, projectName: page.data[i].projectName });
			} */
			projectCombox.setData(projectData);
		}
	});

	// 设置截止日期至今天
	var date = new Date();
	mini.get("calendarDate_to").setValue(date);
	date.setDate(date.getDate() - 5);
	mini.get("calendarDate_from").setValue(date);

	var queryForm = new mini.Form("#queryForm");
	var datagrid = mini.get("datagrid");
	datagrid.set({
		columns: [
			{ type: "indexcolumn" },
			{ width: 160, headerAlign: "center", field: "projectName", header: "项目类别" },
			{ width: 60, headerAlign: "center", field: "costType", header: "成本归类" },
			{ width: 60, headerAlign: "center", field: "departName", header: "部门名称" },
			{ width: 60, headerAlign: "center", field: "workNo", header: "员工工号" },
			{ width: 60, headerAlign: "center", field: "userName", header: "员工名称" },
			{ width: 60, headerAlign: "center", field: "workTime", header: "工作时长" },
			{ width: 60, headerAlign: "center", field: "overTimeDay", header: "平日加班时长" },
			{ width: 60, headerAlign: "center", field: "overTimeWeekend", header: "周末加班时长" },
			{ width: 60, headerAlign: "center", field: "overTimeHoliday", header: "假日加班时长" },
			{ width: 60, headerAlign: "center", field: "totalWorkTime", header: "工作总时长" }
		]
	});

	function doSearch() {
		miniui.mask("数据加载中...");
		var data = queryForm.getData(true, false);
		var node = tree.getSelectedNode();
		if (node) {
			data["departID"] = node.departID;
		} else {
			data["departID"] = 'ROOT';
		}
		http.post("/project/static/project/list.do", data, function (page) {
			if (page.success) {
				debugger
				datagrid.setData(page.data);
			} else {
				miniui.showLoadErrorMessageBox(page.message);
			}
			mini.unmask();
		});
	}

	function output() {
		mini.mask({
			el: document.body,
			cls: 'mini-mask-loading',
			html: '数据处理中...'
		});
		var data = queryForm.getData(true, false);
		var node = tree.getSelectedNode();
		if (node) {
			data["departID"] = node.departID;
			data["departID_link"] = "like";
			data["departName"] = node.departName;
		}
		// debugger
		// data["orderby"] = ["calendarDate,desc"];
		http.post("/project/static/project/output.do", data, function (page) {
			mini.unmask();
			if (page.success) {
				mini.alert("数据处理成功，准备下载!", "提示", null);
				var url = http.getUrl("/file/any/getFile.do");
				jQuery('<form action="' + url + '"method=post">' + // action请求路径及推送方法
					'<input type="text" name="url" value="' + page.dataMap.filename + '"/>' + // 文件路径
					'</form>')
					.appendTo('body').submit().remove();
			} else {
				mini.alert(page.message, "提示", null);
			}
		});
	}
</script>

</html>